﻿using GLWrap.SceneObjects;
using ReAnimation.Helpers.WinForms;

namespace ReAnimation.Graphics.Handlers
{
    public abstract class BaseHandler: IUserActionsHandler
    {
        public IMoleculeDrawer MoleculeDrawer { get; set; }

        protected BaseHandler(IMoleculeDrawer moleculeDrawer)
        {
            MoleculeDrawer = moleculeDrawer;
        }

        public void StartHandle()
        {
            IsActive = true;
            MoleculeDrawer.GlSceneManager.SceneObjectSelected += GlSceneManager_SceneObjectSelected;
            PhysicallyStartHandle();
        }

        private void GlSceneManager_SceneObjectSelected(object sender, EventArg<SceneObject> e)
        {
            SceneObjectSelected(e.Data);
        }

        public void StopHandle()
        {
            MoleculeDrawer.GlSceneManager.SceneObjectSelected -= GlSceneManager_SceneObjectSelected;
            PhysicallyStopHandle();
            IsActive = false;
        }

        public bool IsActive { get; private set; }

        protected virtual void PhysicallyStartHandle()
        {
        }

        protected virtual void PhysicallyStopHandle()
        {
        }

        protected virtual void SceneObjectSelected(SceneObject sceneObject)
        {
        }

    }
}
